/**
   DanmuServiceImpl
 * Time:2018年6月13日
 */
package com.ssm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ssm.dao.DanmuMapper;
import com.ssm.entity.Danmu;
import com.ssm.entity.DanmuExample;
import com.ssm.entity.vo.DanmuSearchVo;
import com.ssm.service.DanmuService;

/**
 * @author 15199
 *
 */
@Service("danmuService")
public class DanmuServiceImpl implements DanmuService {

	/* (non-Javadoc)
	 * @see com.ssm.service.DanmuService#saveDanmu(com.ssm.entity.Danmu)
	 */
	@Resource 
	private DanmuMapper danmuMapper;



	@Override
	public int  saveDanmu(Danmu danmu) {

		// TODO Auto-generated method stub
		if(danmu.getText()!=null&&danmu.getDate()!=null&&danmu.getUserid()!=null&&danmu.getVideoid()!=null){	


			return danmuMapper.insert(danmu);


		}


		return 0;
	}



	/* (non-Javadoc)
	 * @see com.ssm.service.DanmuService#getDanmu()
	 */
	@Override
	public List<Danmu> getDanmu(DanmuSearchVo danmuSearchVo) {
		// TODO Auto-generated method stub


		DanmuExample danmuExample=new DanmuExample();

		if(danmuSearchVo.getUserid()!=null){

			danmuExample.or().andDammuidEqualTo(Integer.parseInt(danmuSearchVo.getUserid()));

		}

		if(danmuSearchVo.getVideoid()!=null){

			danmuExample.or().andVideoidEqualTo(Integer.parseInt(danmuSearchVo.getVideoid()));
			

		}


		danmuExample.setOrderByClause("date desc");


		return danmuMapper.selectByExample(danmuExample);


	}

}
